
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamicSearchField="placeHolder"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsInitTable="false"
      :dynamicIsColumnDrop="false"
      :dynamicButtonsRight="tableButtonsRight"
      @changeToggleProp="changeToggleProp"
    />
  </div>
</template>
<script>
import { crmApis } from "@/api/apiList/crm";
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";

import OneTableTemplate from "@/components/crm/Template/crmonePage";

import Vue from "vue";

export default {
  name: "ToDoTask_ClueCultivation",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate
  },
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(to.path, function() {
      next();
    });
  },
  data() {
    let that=this
    return {
      queryParam: "",
      placeHolder:`客户名称/电话`,
      // 网格查询API配置对象
      apiConfig: crmApis.clueServerQueryFromDlr,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "",
          size: "small",
          clickEvent: () => this.export(),
          // clickEvent: () => this.exportExcel("待办任务线索培育.xlsx", "待办任务线索培育",),
          text: "导出"
        }
      ],
      tableButtonsRight: [
        {
          compKey: "btnKey10001",
          type: "",
          size: "small",
          icon: "el-icon-refresh",
          clickEvent: () => this.resetcur(),
          text: "重置"
        },
        {
          compKey: "btnKey10000",
          type: "primary",
          icon: "el-icon-search",
          size: "small",
          clickEvent: () => this.query(),
          text: "查询"
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableComponents
          : [
              {
                compKey: "compKey1",
                labelName: "客户名称",
                codeField: "custName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey2",
                labelName: "电话",
                codeField: "contactTel",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false
              },

              {
                compKey: "compKey3",
                labelName: "线索单号",
                codeField: "serverOrder",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey4",
                labelName: "回访状态",
                codeField: "reviewStatus",
                lookuptype: "LX831",
                component: () => import("@/components/org/LookupValue"),
                type: "dropdownList",
                isMust: false,
                isMul: false
              },
              {
                compKey: "compKey9",
                labelName: "意向品牌",
                codeField: "carBrandCode",
                textField: "carBrandCn",
                lookuptype: crmApis.mdmCarBrandQueryByPage,
                component: () =>
                  import("@/components/crm/lookupValue/apiDropList"),
                type: "dropdownList",
                isMust: false,
                isMul: false
              },
              {
                compKey: "compKey10",
                labelName: "意向车系",
                codeField: "inteSeriesId",
                component: () =>
                  import(
                    "@/components/crm/crmEjectWindows/crmIntenCarSeries/index"
                  ),
                type: "propus",
                isMust: false,
                isMul: false,
                emitCode:this.inteSeriesChange
              },

              {
                compKey: "compKey8",
                labelName: "意向级别",
                codeField: "clueLevelCode",
                lookuptype: "LX141",
                attribute: "1",
                component: () =>
                  import("@/components/crm/lookupValue/lookupvalue"),
                type: "dropdownList",
                isMust: false,
                isMul: false
              },
              {
                compKey: "compKey13",
                labelName: "单据状态",
                codeField: "status",
                lookuptype: "LX181",
                attribute: "5",
                component: () =>import("@/components/crm/lookupValue/lookupvalue"),
                type: "dropdownList",
                isRequire: false,
                isMust: false
              },
              {
                compKey: "compKey5",
                labelName: "线索渠道",
                codeField: "cantactWayCode",
                textField: "cantactWayName",
                lookuptype: crmApis.pcDbCantactWayQueryFindAll,
                component: () =>
                  import("@/components/crm/lookupValue/singleDropList"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
                changeCode: this.cantactWayChange
              },
              {
                compKey: "cantactWayCode",
                labelName: "一级信息来源",
                codeField: "infoChanMCode",
                textField: "infoChanMName",
                lookuptype: crmApis.pcDbInfoChanMQueryFind,
                changeCodeArray: [{ changCode: "cantactWayCode" }],
                component: () =>
                  import("@/components/crm/lookupValue/secondDropList"), //导入的组件路径
                type: "dropdownList",
                isMust: false,
                isMul: false
              },
              {
                compKey: "compKey14",
                labelName: "二级信息来源",
                codeField: "infoChanDName",
                component: () =>
                  import("@/components/crm/textbox/crmTextInput"),
                type: "",
                isMust: false
              },

              {
                compKey: "compKey11",
                labelName: "下次回访时间",
                codeField: "nextCallbackDateStart,nextCallbackDateEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey12",
                labelName: "建单时间",
                codeField: "createdDateStart,createdDateEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "inputText",
                isMust: false
              },
              // {
              //   compKey: "compKey12",
              //   labelName: "建单时间",
              //   codeField: "createdDateStart,createdDateEnd",
              //   component: () =>
              //     import("@/components/crm/Time/crmdtDatePicker"),
              //   type: "inputText",
              //   isMust: false
              // },
              {
                compKey: "compKey15",
                labelName: "留资时间",
                codeField: "remainDataDateStart,remainDataDateEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "inputText",
                isRequire: false,
                isMust: false
              },
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "controlBtn",
                label: "操作",
                width: 60,
                align: "center",
                codeField: "controlBtn",
                isComponent: true,
                fixed: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "处理",
                    codeField: "editControlBtn",
                    align: "center",
                    isShowLabel: true,
                    isShow: true,
                    clickEvent: index => this.edit(index),
                    // clickEvent: this.edit,
                    component: () => import("@/components/org/linkButton")
                  }
                ]
              },
              {
                prop: "custName",
                label: "客户名称",
                width: 100,
                align: "center",
                fixed: true
              },
              {
                prop: "contactTel",
                label: "电话",
                width: 110,
                align: "center",
                fixed: true
              },
              {
                prop: "serverOrder",
                label: "线索单号",
                width: 160,
                align: "center"
              },
              {
                prop: "crruNodeName",
                label: "作业类型",
                width: 120,
                align: "center"
              },
              {
                prop: "reviewStatusName",
                label: "回访状态",
                width: 100,
                align: "center"
                // hidden:true
              },
              {
                prop: "carBrandName",
                label: "意向品牌",
                width: 120,
                align: "center"
              },
              {
                prop: "carSeriesCn",
                label: "意向车系",
                width: 120,
                align: "center"
              },

              {
                prop: "clueLevelCode",
                label: "意向级别",
                width: 100,
                align: "center"
              },
              {
                prop: "statusName",
                label: "单据状态",
                width: 80,
                align: "center"
              },
              {
                prop: "nextDealEmpName",
                label: "销售顾问",
                width: 100,
                align: "center"
              },
              {
                prop: "createdName",
                label: "建单人",
                width: 140,
                align: "center"
              },

              {
                prop: "cantactWayName",
                label: "线索渠道",
                width: 120,
                align: "center"
              },
              {
                prop: "infoChanMName",
                label: "一级信息来源",
                width: 120,
                align: "center"
                // hidden:true
              },
              {
                prop: "infoChanDName",
                label: "二级信息来源",
                width: 140,
                align: "center"
              },
              {
                prop: "nextCallbackDate",
                label: "下次回访时间",
                width: 150,
                align: "center"
              },
              {
                prop: "createdDate",
                label: "建单时间",
                width: 150,
                align: "center"
              },
               {
                prop: "remainDataDate",
                label: "留资时间",
                width: 150,
                align: "center"
              },


              {
                prop: "phoneForAttr",
                label: "号码归属地",
                width: 120,
                align: "center"
              }
            ],
      // 表单查询数据--重置查询条件
      formField: {
        // oemCode:"1",
        // groupCode: "1",
        custName: "",
        contactTel: "",
        serverOrder: "",
        inteSeriesId: "",
        carBrandCode: "",
        clueLevelCode: "",
        nextCallbackDateStart: "",
        nextCallbackDateEnd: "",
        cantactWayCode: "",
        createdDateStart:that.getStartDate() + " 00:00:00",
        createdDateEnd:that.getEndDate() + " 00:00:00",
        "createdDateStart,createdDateEnd": [
          that.getStartDate() + " 00:00:00",
          that.getEndDate() + " 00:00:00"
        ],
        reviewStatus: "",
        infoChanMCode: "",
        handleCode: "0",
        status:"",
        infoChanDName:"",
        remainDataDateStart:"",
        remainDataDateEnd:"",
        statusArray: ["20", "21", "30"],//后台要求去掉状态31
        clueLevelArray:["A","B","H"]
        // searchValue:"",//搜素字段
      }
    };
  },
  mounted(){
    console.log(this.$route.query.type)
    if(this.$route.query.type){
      this.query()
    }
  },
  methods: {
    inteSeriesChange(row){
      debugger
      this.formField.inteSeriesId=row[0].carSeriesId
    },
    //处理
    edit(index) {
      //跳转到线索回访
      this.$crmcf.jumpDetailTag(
        this,
        "crmThreadReturn",
        "/crmThreadReturn",
        this.$refs.multipleTable.list[index]
      );
    },
    //线索渠道change
    cantactWayChange(){
     this.formField.infoChanMCode=''
    },
    query() {
      let obj = {};
      obj.formField = JSON.parse(JSON.stringify(this.formField));
      this.$delete(obj.formField, "createdDateStart,createdDateEnd");
      this.queryTable(1, null, null, null, null, obj);
    },
    resetcur() {
      this.formField["createdDateStart,createdDateEnd"] = [
        this.getStartDate() + " 00:00:00",
        this.getEndDate() + " 00:00:00"
      ];
      this.reset();
      let patt = new RegExp(","),
        that = this;
      for (let key in that.$refs.multipleTable.$refs) {
        if (
          that.$refs.multipleTable.$refs[key][0] &&
          that.$refs.multipleTable.$refs[key][0].codeField
        ) {
          let flag = patt.test(
            that.$refs.multipleTable.$refs[key][0].codeField
          );
          if (flag) {
            that.$refs.multipleTable.$refs[key][0].modelCode = [];
          }
        }
      }

    },
    getStartDate(){
      let dd = new Date();
      dd.setMonth(dd.getMonth()-1);
      let y = dd.getFullYear();
      let m = dd.getMonth()+1;
      let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      return y + "-" + (m < 10 ? "0" + m : m) + "-" + d;
    },
    getEndDate(){
      let dd = new Date();
      let y = dd.getFullYear();
      let m = dd.getMonth() + 1;
      let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      return y + "-" + (m < 10 ? "0" + m : m) + "-" + d;
    },
    changeToggleProp(){
      this.resetcur()
    },
    export(){
      let obj = {};
      obj.formField = JSON.parse(JSON.stringify(this.formField));
      this.$delete(obj.formField, "createdDateStart,createdDateEnd");
      this.exportExcel("待办任务线索培育.xlsx", "待办任务线索培育",-1,obj )
    }
  }
};
</script>
